<?php

class Quantri_Model_Nhanvien extends Zend_Db_Table_Abstract
{
    protected $_name="dmnhanvien";
    protected $_primary="Id";
    
    var $Id, $HoTen,$NgaySinh,$DiaChi,$DienThoai,$Email,$Trangthai,$TenDangNhap,$MatKhau,$MaQuyen;
    
    public function __construct() {
    	$this->_name = Zend_Registry::get('tablePrefix') . $this->_name;
    	    
    	parent::__construct();
    }
    
	
	public function GetAll() {
	    
        $data = $this->fetchall();
        return $data;
    }
    
    public function GetQuyen() {
    	
    	$query = $this->_db->select()
    	->from(array('T1'=>'os_quyennhanvien'));
    	
    	$stmt = $this->_db->query($query);
    		
    	return $result = $stmt->fetchAll();
    		
    	var_dump($result);
    }
    
    public function Save()
    {
        $data = array(
        	'HoTen' 	=> $this->HoTen,
        	'NgaySinh' 	=> $this->NgaySinh,
        	'DiaChi' 	=> $this->DiaChi,
        	'DienThoai' => $this->DienThoai,
        	'Email' 	=> $this->Email,
        	'Trangthai' => $this->Trangthai,
        	'TenDangNhap' => $this->TenDangNhap,
        	'MatKhau' => $this->MatKhau,
        	'MaQuyen' => $this->MaQuyen,
        );
        
        if($this->Id=="-1")
        	$this->insert($data);
       	else
       	    $this->update($data, "Id = '$this->Id'");
    }
    
    public function XoaNhanVien($id)
    {
        $this->delete("id='". $id . "'");
    }
    
    public function GetById()
    {
        return $this->fetchAll("Id='$this->Id'", "", 1)->toArray();
    }
    
    public function UpdateTrangthai()
    {
        $data = array(
        	'Trangthai' => $this->Trangthai
        );
        
        $this->update($data, "Id = '$this->Id'");
    }
	
}

